import Vue from 'vue'
import Router from 'vue-router';
import utils from '@/utils/index';

Vue.use(Router)

const router = new Router({
  mode: 'history',
  routes: [{ //登录页，不依靠任何组件
      path: '/login',
      name: 'login',
      component: resolve => require(['@/pages/other/login'], resolve),
      meta: {
        withoutAuth: true
      }
    },
    { //核心页面，所有页面基本依赖于layout公共布局文件
      path: '/',
      component: resolve => require(['@/pages/other/layout'], resolve),
      children: [{ //首页
          path: '/home',
          component: resolve => require(['@/pages/index/index.vue'], resolve),
        },
        { //设置页，依赖于右侧导航栏组件
          path: '/set',
          component: resolve => require(['@/pages/other/rightLayout'], resolve),
          children: [{
              path: '',
              component: resolve => require(['@/pages/set/systemConfig/index.vue'], resolve),
            },
            {
              path: 'indexShow',
              component: resolve => require(['@/pages/set/indexShow/index.vue'], resolve),
            },
            {
              path: 'taskPlan',
              component: resolve => require(['@/pages/set/planList/index.vue'], resolve),
            },
            /*{
              path: 'sdk',
              component: resolve => require(['@/pages/set/sdk'], resolve),
            },*/
            {
              path: 'top',
              component: resolve => require(['@/pages/set/inviteRank/index.vue'], resolve),
            },
            {
              path: 'admin',
              component: resolve => require(['@/pages/set/admin/index.vue'], resolve),
            },
            {
              path: 'marketing',
              component: resolve => require(['@/pages/set/marketing/index.vue'], resolve),
            },
          ],
          props: {
            navPage: [{
                name: "系统配置",
                path: "/set/"
              },
              {
                name: "首页显示",
                path: "/set/indexShow/"
              },
              {
                name: "计划任务",
                path: "/set/taskPlan/"
              },
              /*{name:"第三方参数",path:"/set/sdk/"},*/
              {
                name: "邀请排行榜",
                path: "/set/top/"
              },
              {
                name: "管理员账号",
                path: "/set/admin/"
              },
              {
                name: "运营设计",
                path: "/set/marketing/"
              },
            ]
          },
        },
        { //帮助中心
          path: '',
          component: resolve => require(['@/pages/help/index'], resolve),
        },
        { //用户下级管理
          path: '/user/subordinate/:uid',
          component: resolve => require(['@/pages/user/userSubordinate'], resolve),
        },
        { //用户下级管理
          path: '/user/subordinate/:uid/page/:page',
          component: resolve => require(['@/pages/user/userSubordinate'], resolve),
        },
        { //用户管理
          path: '/user',
          component: resolve => require(['@/pages/user/index'], resolve),
        },
        { //用户管理
          path: '/user/page/:page',
          component: resolve => require(['@/pages/user/index'], resolve),
        },
        { //用户管理
          path: '/user/page/:page/:type/:keyword',
          component: resolve => require(['@/pages/user/index'], resolve),
        },
        { //用户详情
          path: '/user/detail/:id',
          component: resolve => require(['@/pages/user/detail'], resolve),
        },
        { //用户模板
          path: '/user/template',
          component: resolve => require(['@/pages/user/template'], resolve),
        },
        { //用户模板详情
          path: '/user/templateDetail',
          component: resolve => require(['@/pages/user/templateDetail'], resolve),
        },
        { //资金页，依赖于右侧导航栏组件
          path: '/capital',
          component: resolve => require(['@/pages/other/rightLayout'], resolve),
          children: [{
              path: 'cash',
              component: resolve => require(['@/pages/capital/cash'], resolve),
              alias: ''
            },
            {
              path: 'recharge',
              component: resolve => require(['@/pages/capital/recharge'], resolve),
            },
            {
              path: 'recharge/page/:page',
              component: resolve => require(['@/pages/capital/recharge'], resolve),
            },
            {
              path: 'recharge/page/:page/:type/:keyword',
              component: resolve => require(['@/pages/capital/recharge'], resolve),
            },
            {
              path: 'detailed',
              component: resolve => require(['@/pages/capital/detailed'], resolve),
            },
            {
              path: 'detailed/page/:page',
              component: resolve => require(['@/pages/capital/detailed'], resolve),
            },
            {
              path: 'detailed/page/:page/:type/:keyword',
              component: resolve => require(['@/pages/capital/detailed'], resolve),
            },
            {
              path: 'integral',
              component: resolve => require(['@/pages/capital/integral'], resolve),
            },
            {
              path: 'integral/page/:page',
              component: resolve => require(['@/pages/capital/integral'], resolve),
            },
            {
              path: 'integral/page/:page/:type/:keyword',
              component: resolve => require(['@/pages/capital/integral'], resolve),
            },
          ],
          props: {
            navPage: [{
                name: "用户提现",
                path: "/capital/",
                getCount: 'cash'
              },
              {
                name: "充值记录",
                path: "/capital/recharge/"
              },
              {
                name: "资金明细",
                path: "/capital/detailed/"
              },
              {
                name: "积分明细",
                path: "/capital/integral/"
              },
            ]
          },
        },
        { //任务板块，依赖于右侧导航栏组件
          path: '/task',
          component: resolve => require(['@/pages/other/rightLayout'], resolve),
          children: [{
              path: '',
              redirect: 'list'
            },
            {
              path: 'list',
              component: resolve => require(['@/pages/task/taskList/index.vue'], resolve),
            },
            {
              path: 'accept',
              component: resolve => require(['@/pages/task/acceptList/index.vue'], resolve),
            },
            {
              path: 'approval',
              component: resolve => require(['@/pages/task/approval/index.vue'], resolve),
            },
            {
              path: 'complaint',
              component: resolve => require(['@/pages/task/complaint/index.vue'], resolve),
            },
            {
              path: 'arbitration',
              component: resolve => require(['@/pages/task/arbitration/index.vue'], resolve),
            },
            {
              path: 'abnormal',
              component: resolve => require(['@/pages/task/abnormal/index.vue'], resolve),
            },
            {
              path: 'systemTemplate',
              component: resolve => require(['@/pages/task/systemTemplateList/index.vue'], resolve),
            },
            {
              path: 'pushSet',
              component: resolve => require(['@/pages/task/pushSet/index.vue'], resolve),
            },
            {
              path: 'class',
              component: resolve => require(['@/pages/task/subject/index.vue'], resolve),
            },
            {
              path: 'preview',
              component: resolve => require(['@/pages/task/userUpload/index.vue'], resolve),
            },
          ],
          props: {
            navPage: [{
                name: "任务列表",
                path: "/task/list/"
              },
              {
                name: "接单列表",
                path: "/task/accept/"
              },
              {
                name: "审批放单",
                path: "/task/approval/",
                getCount: 'check_task'
              },
              {
                name: "用户投诉",
                path: "/task/complaint/",
                getCount: 'report'
              },
              {
                name: "仲裁维权",
                path: "/task/arbitration/",
                getCount: 'arbitration'
              },
              {
                name: "上传一览表",
                path: "/task/preview/"
              },
              {
                name: "异常行为",
                path: "/task/abnormal/",
                getCount: 'user_abnormal'
              },
              {
                name: "分类列表",
                path: "/task/class/"
              },
              {
                name: "发布操作",
                path: "/task/pushSet/"
              },
              {
                name: "系统模板",
                path: "/task/systemTemplate/"
              },
            ]
          },
        },
        { //任务详情
          path: '/task/detail',
          component: resolve => require(['@/pages/task/taskDetail/index.vue'], resolve),
        },
        { //接单详情
          path: '/task/acceptDetail',
          component: resolve => require(['@/pages/task/acceptDetail/index.vue'], resolve),
        },
        { //仲裁详情
          path: '/task/arbitrationDetail',
          component: resolve => require(['@/pages/task/arbitrationDetail/index.vue'], resolve),
        },
        { //系统模板详情
          path: '/task/systemTemplateDetail',
          component: resolve => require(['@/pages/task/systemTemplateDetail/index.vue'], resolve),
        },
        { //项目列表
          path: '/task/project',
          component: resolve => require(['@/pages/task/subjectProject/index.vue'], resolve),
        },
        { //项目详情
          path: '/task/projectDetail',
          component: resolve => require(['@/pages/task/projectDetail/index.vue'], resolve),
        },
        { //增值功能，例如积分签到抽奖页，依赖于右侧导航栏组件
          path: '/increment',
          component: resolve => require(['@/pages/other/rightLayout'], resolve),
          children: [{
              path: 'integral/:tab?',
              component: resolve => require(['@/pages/increment/integral'], resolve),
            },
            {
              path: 'sign',
              component: resolve => require(['@/pages/increment/sign'], resolve),
            },
            {
              path: 'luck',
              component: resolve => require(['@/pages/increment/luck/index.vue'], resolve),
            },
          ],
          props: {
            navPage: [{
                name: "积分商城",
                path: "/increment/integral/"
              },
              {
                name: "签到",
                path: "/increment/sign/"
              },
              {
                name: "抽奖",
                path: "/increment/luck/"
              },
            ]
          },
        },
        { //积分，发货详情
          path: '/increment/integralDeliver/:id',
          component: resolve => require(['@/pages/increment/integralDeliver'], resolve),
        },
        { //积分，商品详情
          path: '/increment/integralShopDetail',
          name: 'goodsDetail',
          component: resolve => require(['@/pages/increment/integralShopDetail'], resolve),
        },
        { //活动
          path: '/increment/integralShopDetail',
          name: 'goodsDetail',
          component: resolve => require(['@/pages/increment/integralShopDetail'], resolve),
        },
        { //活动
          path: '/active',
          name: 'active',
          component: resolve => require(['@/pages/other/rightLayout'], resolve),
          children: [{
              path: 'statistics',
              component: resolve => require(['@/pages/active/statistics'], resolve),
            },{
              path: 'statisticsChance',
              component: resolve => require(['@/pages/active/statisticsChance'], resolve),
            },{
              path: 'win',
              component: resolve => require(['@/pages/active/win'], resolve),
            }],
            props: {
              navPage: [{
                  name: "抽奖统计",
                  path: "/active/statistics/"
                },{
                  name: "抽奖机会统计",
                  path: "/active/statisticsChance/"
                },{
                  name: "中奖明细",
                  path: "/active/win/"
                },
              ]
            },
        },






      ]
    },
    {
      path: '(.*)',
      redirect: '/',
    }
  ]
})

router.beforeEach((to, from, next) => {
  let auth_key = utils.handleLocalStorage.get('authorized_key');
  if (to.meta.withoutAuth) {
    next();
  } else {
    if (auth_key) {
      next();
    } else {
      next({
        path: '/login',
        query: {
          redirect: to.fullPath
        }
      });
    }
  }
});

export default router;
